package com.my.demo.shiro.redis;
import java.util.Collection;
import java.util.Set;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;

//自定义redis缓存的实现
@Component
public class RedisCache<k,v> implements Cache<k,v> {

  private RedisTemplate redisTemplate;

  public RedisTemplate getRedisTemplate() {
    return redisTemplate;
  }

  public void setRedisTemplate(RedisTemplate redisTemplate) {
    this.redisTemplate = redisTemplate;
  }

  @Override
  public v get(k k) throws CacheException {
    System.out.println("get key:"+k);
    return (v)redisTemplate.opsForValue().get(k.toString());
  }

  @Override
  public v put(k k, v v) throws CacheException {
    System.out.println("put key:"+k);
    System.out.println("put value:"+v);
    redisTemplate.opsForValue().set(k.toString(), v.toString());
    return v;
  }

  @Override
  public v remove(k k) throws CacheException {
    return null;
  }

  @Override
  public void clear() throws CacheException {

  }

  @Override
  public int size() {
    return 0;
  }

  @Override
  public Set<k> keys() {
    return null;
  }

  @Override
  public Collection<v> values() {
    return null;
  }


}

